package com.pengcheng.taskapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.model.ParkOrderModel;
import com.pengcheng.taskapplication.model.WalletModel;
import com.pengcheng.taskapplication.model.WashOrderModel;
import com.pengcheng.taskapplication.mvp.view.widget.CircleImageView;
import com.pengcheng.taskapplication.net.ConvertUtil;

import java.text.DecimalFormat;
import java.util.List;

public class WashAdapter extends BaseAdapter {

    Context context;
    LayoutInflater inflater;
    List<WashOrderModel> washOrderModels;
    int last_item;
    private int selectedPosition = -1;

    public WashAdapter(Context context, List<WashOrderModel> washOrderModels) {
        this.context = context;
        this.washOrderModels = washOrderModels;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return washOrderModels.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return washOrderModels.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.activity_wash_item_layout, null);
            holder = new ViewHolder();
            holder.tv_order = (TextView) convertView.findViewById(R.id.tv_order);
            holder.tv_cost = (TextView) convertView.findViewById(R.id.tv_cost);
            holder.tv_wash_type_name = (TextView) convertView.findViewById(R.id.tv_wash_type_name);
            holder.tv_f_time_show = (TextView) convertView.findViewById(R.id.tv_f_time_show);
            holder.tv_order_status = (TextView) convertView.findViewById(R.id.tv_order_status);
            holder.tv_order_pay_type=(TextView)convertView.findViewById(R.id.tv_order_pay_type);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        WashOrderModel model = washOrderModels.get(position);
        holder.tv_order.setText(model.getCarnumber()+"");
        holder.tv_cost.setText("￥" + ConvertUtil.getFormateMoney(model.getMoney() / 100));
        holder.tv_wash_type_name.setText(model.getWashtype().equals("finewash") ? "精洗" : "普通洗");
        holder.tv_f_time_show.setText(ConvertUtil.getDateToShortString(model.getUpdatetime()));
       // holder.tv_order_status.setText(model.getStatus() == 0 ? "待支付" : "已完成");

        switch (model.getPayway()){
            case 2:
                holder.tv_order_pay_type.setText("微信支付");
                break;
            case 3:
                holder.tv_order_pay_type.setText("支付宝支付");
                break;
            case 4:
                holder.tv_order_pay_type.setText("银行卡支付");
                break;
        }



        if (model.getStatus() == 0) {
            holder.tv_order_status.setText("待支付");
            holder.tv_order_status.setTextColor(context.getResources().getColor(R.color.l_gray));
        } else if (model.getStatus() == 1) {
            int endStatus = model.getEndstatus();
            if (endStatus == 0) {
                holder.tv_order_status.setText("进行中");
                holder.tv_order_status.setTextColor(context.getResources().getColor(R.color.linsece_top));
            } else if (endStatus == 1) {
                holder.tv_order_status.setText("自动完成");
                holder.tv_order_status.setTextColor(context.getResources().getColor(R.color.l_gray));
            } else if (endStatus == 2) {
                holder.tv_order_status.setText("手动中止");
                holder.tv_order_status.setTextColor(context.getResources().getColor(R.color.l_gray));
            } else if (endStatus == 3) {
                holder.tv_order_status.setText("未开始");
                holder.tv_order_status.setTextColor(context.getResources().getColor(R.color.l_gray));
            }
        }

        return convertView;
    }

    public static class ViewHolder {
        public TextView tv_order;
        public TextView tv_cost;
        public TextView tv_wash_type_name;
        public TextView tv_f_time_show;
        public TextView tv_order_status;

        public TextView tv_order_pay_type;

        public CircleImageView circleImage;

    }

    public void setSelectedPosition(int position) {
        selectedPosition = position;
    }

    public interface OnStopLisener {
        void onStop(WashOrderModel washOrderModel);
    }

    private OnStopLisener onStopLisner;

    public void setOnStopLisner(OnStopLisener onStopLisner) {
        this.onStopLisner = onStopLisner;
    }
}
